package in.muton.edushare.pages.coursepages;

import java.util.Arrays;

import in.muton.edushare.grading.panels.CourseGradePanel;

import java.util.Arrays;

import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Enrolments;

public class CourseGrading extends CourseBase {

	public CourseGrading(PageParameters params) {
		super(params);
		prc.check(Arrays.asList(Enrolments.TEACHER));
		add(JavascriptPackageResource.getHeaderContribution(
				CourseGradePanel.class, "grade.js"));
		add(wmc1 = new WebMarkupContainer("tab1"));
		add(wmc2 = new WebMarkupContainer("tab2"));
		add(wmc3 = new WebMarkupContainer("tab3"));

		wmc1.add(new AttributeAppender("class", new Model<String>() {
			private static final long serialVersionUID = 1075106829892837637L;

			@Override
			public String getObject() {
				if (getActivePanel() == GRADE_COMPONENTS
						|| getActivePanel() == NEW_GRADE_COMPONENT)
					return "es-fbTabItemSelected";
				return "es-fbTabItem";
			}

		}, " "));

		wmc2.add(new AttributeAppender("class", new Model<String>() {
			private static final long serialVersionUID = 1075106829892837637L;

			@Override
			public String getObject() {
				if (getActivePanel() == COURSE_GRADES)
					return "es-fbTabItemSelected";
				return "es-fbTabItem";
			}

		}, " "));

		wmc3.add(new AttributeAppender("class", new Model<String>() {
			private static final long serialVersionUID = 1075106829892837637L;

			@Override
			public String getObject() {
				if (getActivePanel() == GRADE_KEY)
					return "es-fbTabItemSelected";
				return "es-fbTabItem";
			}

		}, " "));

		wmc1.add(new Link<Void>("link") {
			private static final long serialVersionUID = 1275662926426075680L;

			@Override
			public void onClick() {
				setActivePanel(GRADE_COMPONENTS);
			}
		});
		wmc2.add(new Link<Void>("link") {
			private static final long serialVersionUID = 1275662926426075680L;

			@Override
			public void onClick() {
				setActivePanel(COURSE_GRADES);
			}
		});
		wmc3.add(new Link<Void>("link") {
			private static final long serialVersionUID = 1275662926426075680L;

			@Override
			public void onClick() {
				setActivePanel(GRADE_KEY);
			}
		});
		add(new CourseGradePanel("gradingPanel", this, getCourseInstance()));
	}

	@Override
	protected String getActivePage(PageParameters params) {
		return "CourseGrading";
	}

	@Override
	public String getPageTitle() {
		return getLoggedInUser().getCompleteUserName() + " | "
				+ getCourse().getObject().getCourseName() + " | Grading | "
				+ ApplicationConstants.APPLICATION_NAME;
	}

	public static final int GRADE_COMPONENTS = 10;
	public static final int COURSE_GRADES = 20;
	public static final int GRADE_KEY = 30;
	public static final int NEW_GRADE_COMPONENT = 40;

	public void setActivePanel(int activePanel) {
		this.activePanel = activePanel;
	}

	public int getActivePanel() {
		return activePanel;
	}

	private int activePanel = GRADE_COMPONENTS;
	private WebMarkupContainer wmc1, wmc2, wmc3;
}
